package cn.com.servyou.utils;

import cn.com.servyou.model.vo.ReturnPageDataVo;

/**
 * 返回结果对象构造器
 */
public class RestResultGenerator {

    // 查询失败
    public static ReturnPageDataVo genResult(String msg){
        ReturnPageDataVo result = new ReturnPageDataVo();
        result.setCode("400");
        result.setMsg(msg);
        //return JSONObject.parseObject(JSON.toJSON(result).toString());
        return result;
    }

    // 操作失败
    public static ReturnPageDataVo genResult(String code, String msg){
        ReturnPageDataVo result = new ReturnPageDataVo();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

    // 有查询结果，查询成功
    public static ReturnPageDataVo genResult(Object data){
        return RestResultGenerator.genResult(data, null);
    }

    //无参返回成功
    public static ReturnPageDataVo genResult(){
        ReturnPageDataVo result = new ReturnPageDataVo();
        result.setCode("600");
        result.setMsg("");
        //return  JSONObject.parseObject(JSON.toJSON(result).toString());
        return result;
    }

    // 有查询结果列表数据
    public static ReturnPageDataVo genResult(Object data, Integer total){
        ReturnPageDataVo result = new ReturnPageDataVo();
        result.setCode("600");
        result.setMsg("");
        result.setData(data);
        result.setTotal(total);
        return result;
    }

}

